package com.kyub.buganville

import grails.test.*

class IssueTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSave() {
     def testInstances=[]
     mockDomain(Issue, testInstances)
     def user = new User(username: 'me', enabled: true, password: 'password')
     mockDomain(User,[user])
     def artifact = new Artifact(name:"demo artifact" , description:"Demo demo demo")         
     mockDomain(Artifact,[artifact])

      Issue iok = new Issue(title :"Test Issue", content:"SBIDIGUDA SBIDIGUDA", priority:Priority.HIGH, status:IssueStatus.OPEN, type:IssueType.BLOCKER, opener:user, artifact:artifact)

     if(iok.validate() ){
     iok.save()

      assertNotNull(iok.id)
      assertNotNull(iok.lastUpdated)
      assertNotNull(iok.dateCreated)
       }
      else{
       println(iok.errors )
       fail("Validation fails")
     }

    Issue iNoRelations = new Issue(title :"Test Issue", content:"SBIDIGUDA SBIDIGUDA", priority:Priority.HIGH, status:IssueStatus.OPEN, type:IssueType.BLOCKER)

    assertFalse(iNoRelations.validate())

    Issue iNoEnums = new Issue(title :"Test Issue", content:"SBIDIGUDA SBIDIGUDA", opener:user, artifact:artifact)

    assertFalse(iNoEnums.validate())

    }
}
